import http from "@/utils/http";

// ### 加入bus
export function JoinBus(params: {
    busId: number
}): Promise<{
    code: 10 | 11 | 12 // ? code 10=已满员 11=自己的bus 12=已上车
}> {
    return http.post(`/api/bactroban-bus/joinBus`, params)
}

// ### 发车
export enum BUS_THEME {
    'ZHUDI' = 1,
    'NIKE' = 2
}

export function StartBus(params: {
    theme: BUS_THEME.ZHUDI | BUS_THEME.NIKE    // ? 1=ZhuDi 2=Nike
}): Promise<BusProps> {
    return http.post(`/api/bactroban-bus/startBus`, params).then(res => res?.data)
}

// ### 查询自己是否发车
export type BusProps = {
    create_time: string
    id: number
    num: number
    passengers: {
        bus_id: number
        create_time: string
        head: string
        id: number
        name: string
        user_id: number
    }[]
    user_id: number
    theme: BUS_THEME
}
export function Bus() {
    return http.post(`/api/bactroban-bus/bus`).then<BusProps[]>(res => res?.data)
}

// ### 根据id获取发车详情
export function BusDetail(params: {
    id: number | string
}) {
    return http.get(`/api/bactroban-bus/detail`, { params }).then<BusProps>(res => res?.data)
}

// ### 关联头像与Bus
export function BusHead(params: {
    busId: number
    head: string
}) {
    return http.post(`/api/bactroban-bus/busHead`, params)
}